package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.mybatisplus.model.domain.FavouriteMovie;
import com.example.mybatisplus.mapper.FavouriteMovieMapper;
import com.example.mybatisplus.model.domain.WhitelistSetting;
import com.example.mybatisplus.service.FavouriteMovieService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author
 * @since 2024-11-08
 */
@Service
public class FavouriteMovieServiceImpl extends ServiceImpl<FavouriteMovieMapper, FavouriteMovie> implements FavouriteMovieService {

    @Autowired
    private FavouriteMovieMapper favouriteMovieMapper;


    @Override
    public List<FavouriteMovie> getFavouriteMoviesByUserId(Long userId) {
        return favouriteMovieMapper.selectByUserId(userId);
    }

    @Override
    public FavouriteMovie saveFavouriteMovie(FavouriteMovie favouriteMovie) {
        favouriteMovieMapper.insertFavouriteMovie(favouriteMovie);
        return favouriteMovie;
    }

    @Override
    public int deleteByMvId(Long mvId) {
        return this.baseMapper.deleteByMvId(mvId);
    }

    @Override
    public boolean isFavourited(FavouriteMovie favouriteMovie) {
        QueryWrapper<FavouriteMovie> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", favouriteMovie.getUserId())
                .eq("mv_name", favouriteMovie.getMvName());
        FavouriteMovie one =baseMapper.selectOne(wrapper);
        if(one != null) return true;
        return false;
    }
}
